/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "bill")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Bill.findAll", query = "SELECT b FROM Bill b"),
    @NamedQuery(name = "Bill.findByPeriodId", query = "SELECT b FROM Bill b WHERE b.billPK.periodId = :periodId"),
    @NamedQuery(name = "Bill.findByPeriodIdByBillId", query = "SELECT b FROM Bill b WHERE b.billPK.periodId = :periodId AND b.billPK.billId = :billId"),
    @NamedQuery(name = "Bill.findByBillId", query = "SELECT b FROM Bill b WHERE b.billPK.billId = :billId"),
    @NamedQuery(name = "Bill.findByDate", query = "SELECT b FROM Bill b WHERE b.date = :date"),
    @NamedQuery(name = "Bill.findByClient", query = "SELECT b FROM Bill b WHERE b.client = :client"),
    @NamedQuery(name = "Bill.findByBillNum", query = "SELECT b FROM Bill b WHERE b.billNum = :billNum"),
    @NamedQuery(name = "Bill.findByNit", query = "SELECT b FROM Bill b WHERE b.nit = :nit"),
    @NamedQuery(name = "Bill.findByAmount", query = "SELECT b FROM Bill b WHERE b.amount = :amount"),
    @NamedQuery(name = "Bill.findBillIdIdMax", query = "SELECT max(b.billPK.billId) FROM Bill b"),
    @NamedQuery(name = "Bill.findByControlCode", query = "SELECT b FROM Bill b WHERE b.controlCode = :controlCode"),
    @NamedQuery(name = "Bill.findByActive", query = "SELECT b FROM Bill b WHERE b.active = :active")})
public class Bill implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected BillPK billPK;
    @Basic(optional = false)
    @Column(name = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Basic(optional = false)
    @Column(name = "client")
    private boolean client;
    @Basic(optional = false)
    @Column(name = "billNum")
    private int billNum;
    @Basic(optional = false)
    @Column(name = "nit")
    private String nit;
    @Basic(optional = false)
    @Column(name = "amount")
    private float amount;
    @Basic(optional = false)
    @Column(name = "controlCode")
    private String controlCode;
    @Column(name = "active")
    private Boolean active;
    @JoinColumn(name = "dosageId", referencedColumnName = "dosageId")
    @ManyToOne(optional = false)
    private Dosage dosageId;
    @OneToMany(mappedBy = "bill")
    private Collection<Transaction> transactionCollection;

    public Bill() {
    }

    public Bill(BillPK billPK) {
        this.billPK = billPK;
    }

    public Bill(BillPK billPK, Date date, boolean client, int billNum, String nit, float amount, String controlCode) {
        this.billPK = billPK;
        this.date = date;
        this.client = client;
        this.billNum = billNum;
        this.nit = nit;
        this.amount = amount;
        this.controlCode = controlCode;
    }

    public Bill(int periodId, int billId) {
        this.billPK = new BillPK(periodId, billId);
    }

    public BillPK getBillPK() {
        return billPK;
    }

    public void setBillPK(BillPK billPK) {
        this.billPK = billPK;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public boolean getClient() {
        return client;
    }

    public void setClient(boolean client) {
        this.client = client;
    }

    public int getBillNum() {
        return billNum;
    }

    public void setBillNum(int billNum) {
        this.billNum = billNum;
    }

    public String getNit() {
        return nit;
    }

    public void setNit(String nit) {
        this.nit = nit;
    }

    public float getAmount() {
        return amount;
    }

    public void setAmount(float amount) {
        this.amount = amount;
    }

    public String getControlCode() {
        return controlCode;
    }

    public void setControlCode(String controlCode) {
        this.controlCode = controlCode;
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

    public Dosage getDosageId() {
        return dosageId;
    }

    public void setDosageId(Dosage dosageId) {
        this.dosageId = dosageId;
    }

    @XmlTransient
    public Collection<Transaction> getTransactionCollection() {
        return transactionCollection;
    }

    public void setTransactionCollection(Collection<Transaction> transactionCollection) {
        this.transactionCollection = transactionCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (billPK != null ? billPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Bill)) {
            return false;
        }
        Bill other = (Bill) object;
        if ((this.billPK == null && other.billPK != null) || (this.billPK != null && !this.billPK.equals(other.billPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Bill[ billPK=" + billPK + " ]";
    }
    
}
